package com.gitee.zycra.union.api.manager;

import com.gitee.zycra.union.api.common.model.ApiInterfaceFolder;
import com.gitee.zycra.union.api.common.util.IdGenerator;
import com.gitee.zycra.union.api.common.vo.InterfaceFolderVO;
import com.gitee.zycra.union.api.dao.ApiInterfaceFolderDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zycra
 */
@Component
public class ApiInterfaceFolderManager {

    @Autowired
    private ApiInterfaceFolderDao apiInterfaceFolderDao;

    @Autowired
    private IdGenerator idGenerator;

    /**
     * 添加目录
     *
     * @param projectId  项目ID
     * @param folderName 目录名称
     * @return 添加结果
     */
    public int addFolder(Long projectId, String folderName) {
        return apiInterfaceFolderDao.insert(new ApiInterfaceFolder().setId(idGenerator.nextId()).setProjectId(projectId).setFolderName(folderName));
    }

    /**
     * 根据ID更新目录
     *
     * @param id         目录ID
     * @param folderName 目录名称
     * @return 添加结果
     */
    public int updateFolder(Long id, String folderName) {
        return apiInterfaceFolderDao.update(new ApiInterfaceFolder().setId(id).setFolderName(folderName));
    }

    /**
     * 根据ID删除目录
     *
     * @param id 目录ID
     * @return 添加结果
     */
    public int deleteFolder(Long id) {
        return apiInterfaceFolderDao.updateToDelete(id);
    }

    /**
     * 根据项目ID查询目录
     *
     * @param projectId 项目ID
     * @return 目录集合
     */
    public List<InterfaceFolderVO> selectByProjectId(Long projectId) {
        return apiInterfaceFolderDao.selectByProjectId(projectId);
    }
}
